import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
	{
		path: "/",
		name: "Home",
		component: Home,
		redirect: "detail",
		meta: {
			title: "网易云音乐",
		},
		children: [
			{
				path: "detail",
				name: "detail",
				redirect: "detail/recommend",
				component: () => import("@/views/detail.vue"),
				meta: {
					title: "网易云音乐",
				},
				children: [
					{
						path: "recommend",
						name: "recommend",
						component: () => import("@/views/recommend.vue"),
						meta: {
							title: "网易云音乐",
						},
					},
				],
			},

			{
				path: "particulars/:id&:name",
				name: "particulars",
				component: () => import("@/views/particulars.vue"),
				meta: {
					title: "网易云音乐",
				},
			},
		],
	},
	{
		path: "songList/:id&:name",
		name: "songList",
		component: () => import("@/views/songList.vue"),
		meta: {
			title: "网易云音乐",
		},
	},
];

const router = new VueRouter({
	// mode: "history",
	base: process.env.BASE_URL,
	routes,
});

router.beforeEach((to, from, next) => {
	if (to.meta.title) {
		document.title = to.meta.title;
	}
	next();
});
export default router;
